package edu.study.api.common.dto;

import com.fasterxml.jackson.core.type.TypeReference;
import edu.study.api.common.json.JsonUtils;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.SerializationUtils;

import java.io.Serializable;

@Setter
@Getter
public abstract class BaseDto implements Serializable, Cloneable {

	public static String toString(Object object) {
        return JsonUtils.toInsensitiveJson(object);
    }

    public static String toJsonStr(Object object) {
        return JsonUtils.toJson(object);
    }


    public static <T> T fromJson(String json, Class<T> classOfT) {
        return JsonUtils.fromJson(json, classOfT);
    }

    public static <T> T fromJson(String json, TypeReference<T> typeRef) {
        return JsonUtils.fromJson(json, typeRef);
    }

    public String toJson() {
        return JsonUtils.toJson(this);
    }

    public String toJson(Object object) {
        return JsonUtils.toJson(object);
    }

    @Override
    public String toString() {
        return JsonUtils.toInsensitiveJson(this);
    }

    @Override
    public Object clone() {
        return SerializationUtils.clone(this);
    }
}
